﻿/*-----------------------------------------------------------------------
 * <copyright file="WCFOPCorrelation.svc.cs" company="O-RID">
 *     Copyright (c)2010 O-RID Co.,Ltd.
 * </copyright>
 * <author>Zhang Jun</author>
 * <summary>
 *          所有与OP信息操作相关的所有服务
 *          StatisticsToolsDB_new 数据库
 *
 *          作成日：07/07/2010
 *          
 *                  06/09/2011 增加 OP别日别查询、OP别期间别查询 追加案件名，线路选项
 *                  
 * </summary>
 *-----------------------------------------------------------------------
 */
namespace Orid.Management.Statistics.Service.OPUnitService.OPCorrelation
{
    using System;
    using System.Collections.Generic;
    using System.ServiceModel;
    using System.ServiceModel.Activation;
    using Orid.Management.Statistics.Service.OPUnitService.OPCorrelation.ServiceModel;

    /// <summary>
    /// 注意: 如果更改此处的类名 "WCFOPCorrelation"，也必须更新 Web.config 中对 "WCFOPCorrelation" 的引用。
    /// </summary>
    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class WCFOPCorrelation : IWCFOPCorrelation
    {
        #region OP别 日别 查询
        /// <summary>
        /// 显示 所有 符合查询条件的OP信息
        /// WCFOPEntrySpeedQuery服务
        /// OPEntrySpeedQueryControl.xaml
        /// 中的DataGrid中使用
        /// </summary>
        /// <param name="whereParameter">The where parameter.</param>
        /// <returns>
        /// 返回 OPDurationEntrySpeedQueryInforData 的 LIST 形式
        /// </returns>
        public List<OPEntrySpeedQueryInforDataList> SelectOPEntrySpeedQueryInfor(WhereParameters whereParameter)
        {
            try
            {
                //// 06/02/2010 修改 GetSelectOPEntrySpeedQueryInfor为存储过程 所以参数形式变更

                #region 参数形式转换

                ////日期
                if (!whereParameter.WhereentryDateFrom.Equals("null"))
                {
                    whereParameter.WhereentryDateFrom = whereParameter.WhereentryDateFrom.ToString().Trim();
                }

                if (!whereParameter.WhereentryDateTo.Equals("null"))
                {
                    whereParameter.WhereentryDateTo = whereParameter.WhereentryDateTo.ToString().Trim();
                }

                ////jobclass
                if (String.IsNullOrEmpty(whereParameter.WhereJobClass))
                {
                    whereParameter.WhereJobClass = DBNull.Value.ToString();
                }
                else
                {
                    whereParameter.WhereJobClass = whereParameter.WhereJobClass.ToString().Trim();
                }

                ////ScriptType
                if (String.IsNullOrEmpty(whereParameter.WhereScriptType))
                {
                    whereParameter.WhereScriptType = DBNull.Value.ToString();
                }
                else
                {
                    whereParameter.WhereScriptType = whereParameter.WhereScriptType.ToString().Trim();
                }

                ////WordType
                if (String.IsNullOrEmpty(whereParameter.WhereWordType))
                {
                    whereParameter.WhereWordType = DBNull.Value.ToString();
                }
                else
                {
                    whereParameter.WhereWordType = whereParameter.WhereWordType.ToString().Trim();
                }

                ////是opid
                if (!string.IsNullOrEmpty(whereParameter.WhereLoginName))
                {
                    whereParameter.WhereLoginName = whereParameter.WhereLoginName.Trim();
                }
                else
                {
                    whereParameter.WhereLoginName = DBNull.Value.ToString();
                }

                ////是UNIT
                if (!string.IsNullOrEmpty(whereParameter.WhereUnit))
                {
                    whereParameter.WhereUnit = whereParameter.WhereUnit.Trim();
                }
                else
                {
                    whereParameter.WhereUnit = DBNull.Value.ToString();
                }

                ////案件名 
                if (!string.IsNullOrEmpty(whereParameter.WhereMatterName))
                {
                    whereParameter.WhereMatterName = whereParameter.WhereMatterName.Trim();
                }
                else
                {
                    whereParameter.WhereMatterName = DBNull.Value.ToString();
                }

                ////线路
                if (!string.IsNullOrEmpty(whereParameter.WhereServer))
                {
                    whereParameter.WhereServer = whereParameter.WhereServer.Trim();
                }
                else
                {
                    whereParameter.WhereServer = DBNull.Value.ToString();
                }

                #endregion

                return DataProvider.GetSelectOPEntrySpeedQueryInfor(whereParameter);
            }
            catch (Exception ex)
            {
                Log4Service.Log log = new Orid.Management.Statistics.Service.Log4Service.Log();
                log.Error("WCFOPEntrySpeedQuery SelectOPEntrySpeedQueryInfor Error:" + ex.Message);
            }

            return null;
        }
        #endregion OP别 日别 查询

        #region OP别 期间别 查询
        /// <summary>
        /// 显示 所有OP别期间别信息
        /// WCFOPDurationEntrySpeedQuery服务
        /// OPEntrySpeedQueryControl.xaml
        /// </summary>
        /// <param name="whereParametersList">where 条件列表</param>
        /// <returns>
        /// 返回 OPDurationEntrySpeedQueryInforData 的 LIST 形式
        /// </returns>
        public List<OPDurationEntrySpeedQueryInforData> SelectOPDurationEntrySpeedQueryInfor(List<WhereParameters> whereParametersList)
        {
            try
            {
                #region 参数形式转换

                ////日期
                if (!whereParametersList[0].WhereentryDateFrom.Equals("null"))
                {
                    whereParametersList[0].WhereentryDateFrom = whereParametersList[0].WhereentryDateFrom.ToString().Trim();
                }

                if (!whereParametersList[0].WhereentryDateTo.Equals("null"))
                {
                    whereParametersList[0].WhereentryDateTo = whereParametersList[0].WhereentryDateTo.ToString().Trim();
                }

                ////jobclass
                if (String.IsNullOrEmpty(whereParametersList[0].WhereJobClass))
                {
                    whereParametersList[0].WhereJobClass = DBNull.Value.ToString();
                }
                else
                {
                    whereParametersList[0].WhereJobClass = whereParametersList[0].WhereJobClass.ToString().Trim();
                }

                ////ScriptType
                if (String.IsNullOrEmpty(whereParametersList[0].WhereScriptType))
                {
                    whereParametersList[0].WhereScriptType = DBNull.Value.ToString();
                }
                else
                {
                    whereParametersList[0].WhereScriptType = whereParametersList[0].WhereScriptType.ToString().Trim();
                }

                ////WordType
                if (String.IsNullOrEmpty(whereParametersList[0].WhereWordType))
                {
                    whereParametersList[0].WhereWordType = DBNull.Value.ToString();
                }
                else
                {
                    whereParametersList[0].WhereWordType = whereParametersList[0].WhereWordType.ToString().Trim();
                }

                ////是opid
                if (!string.IsNullOrEmpty(whereParametersList[0].WhereLoginName))
                {
                    whereParametersList[0].WhereLoginName = whereParametersList[0].WhereLoginName.Trim();
                }
                else
                {
                    whereParametersList[0].WhereLoginName = DBNull.Value.ToString();
                }

                ////是UNIT
                if (!string.IsNullOrEmpty(whereParametersList[0].WhereUnit))
                {
                    whereParametersList[0].WhereUnit = whereParametersList[0].WhereUnit.Trim();
                }
                else
                {
                    whereParametersList[0].WhereUnit = DBNull.Value.ToString();
                }

                ////案件名 
                if (!string.IsNullOrEmpty(whereParametersList[0].WhereMatterName))
                {
                    whereParametersList[0].WhereMatterName = whereParametersList[0].WhereMatterName.Trim();
                }
                else
                {
                    whereParametersList[0].WhereMatterName = DBNull.Value.ToString();
                }

                ////线路
                if (!string.IsNullOrEmpty(whereParametersList[0].WhereServer))
                {
                    whereParametersList[0].WhereServer = whereParametersList[0].WhereServer.Trim();
                }
                else
                {
                    whereParametersList[0].WhereServer = DBNull.Value.ToString();
                }

                #endregion

                return DataProvider.GetSelectOPDurationEntrySpeedQueryInfor(whereParametersList);
            }
            catch (Exception ex)
            {
                Log4Service.Log log = new Orid.Management.Statistics.Service.Log4Service.Log();
                log.Error("WCFOPDurationEntrySpeedQuery SelectOPDurationEntrySpeedQueryInfor Error:" + ex.Message);
            }

            return null;
        }

        #endregion OP别 期间别 查询

        #region OP别 稼动率 查询
        /// <summary>
        /// OP稼动率 查询
        /// OPWorkEfficiencyQueryControl.xaml
        /// 中的DataGrid使用
        /// </summary>
        /// <param name="WhereParametersForWorkEff">where 的参数列表</param>
        /// <returns>返回 WorkEfficiencyDataList 的LIST 形式</returns>
        public List<WorkEfficiencyDataList> SelectOPWorkEfficiency(List<WhereParametersForWorkEff> whereParametersList) 
        {
            try
            {
                List<WorkEfficiencyDataList> retWorkEfficiencyList = null;

                #region 参数形式转换

                ////日期
                if (!whereParametersList[0].WhereentryDateFrom.Equals("null"))
                {
                    whereParametersList[0].WhereentryDateFrom = whereParametersList[0].WhereentryDateFrom.ToString().Trim();
                }

                if (!whereParametersList[0].WhereentryDateTo.Equals("null"))
                {
                    whereParametersList[0].WhereentryDateTo = whereParametersList[0].WhereentryDateTo.ToString().Trim();
                }

                if (!string.IsNullOrEmpty(whereParametersList[0].WhereLoginName))
                {
                    ////是opid
                    whereParametersList[0].WhereLoginName = whereParametersList[0].WhereLoginName.Trim();
                }
                else
                {
                    whereParametersList[0].WhereLoginName = DBNull.Value.ToString();
                }

                if (!string.IsNullOrEmpty(whereParametersList[0].WhereUnit))
                {
                    ////是UNIT
                    whereParametersList[0].WhereUnit = whereParametersList[0].WhereUnit.Trim();
                }
                else
                {
                    whereParametersList[0].WhereUnit = DBNull.Value.ToString();
                }

                #endregion 参数设置

                string procedureName = string.Empty;

                if (!string.IsNullOrEmpty(whereParametersList[0].WhereStatsticClass))
                {
                    switch (whereParametersList[0].WhereStatsticClass.ToString().Trim().ToUpper())
                    {
                        case "DAY":
                            retWorkEfficiencyList = DataProvider.GetSelectOPWorkEfficiencyDay(whereParametersList);
                            break;

                        case "HOUR":
                            retWorkEfficiencyList = DataProvider.GetSelectOPWorkEfficiencyHour(whereParametersList);
                            break;
                    }
                }

                return retWorkEfficiencyList;
            }
            catch (Exception ex) 
            {
                Log4Service.Log log = new Orid.Management.Statistics.Service.Log4Service.Log();
                log.Error("WCFOPWorkEfficiencyQuery SelectWorkEfficiency Error:" + ex.Message);
            }

            return null;
        }
        #endregion OP别 稼动率 查询

        #region OP别 总成绩
        /// <summary>
        /// SelectOPScore
        /// OP成绩查询
        /// </summary>
        /// <param name="parameters">parameters 条件参数列表</param>
        /// <returns>返回 ScoreData 的 LIST 形式</returns>
        public List<ScoreData> SelectOPScore(WhereParameters parameters)
        {
            try
            {
                #region 参数形式转换
                ////日期
                if (!parameters.WhereentryDateFrom.Equals("null"))
                {
                    parameters.WhereentryDateFrom = parameters.WhereentryDateFrom.ToString().Trim() + " 06:00:00";
                }

                if (!parameters.WhereentryDateTo.Equals("null"))
                {
                    parameters.WhereentryDateTo = parameters.WhereentryDateTo.ToString().Trim() + " 06:00:00";
                }

                #endregion 参数设置

                return DataProvider.GetSelectEntryScore(parameters);
            }
            catch (Exception ex)
            {
                Log4Service.Log log = new Orid.Management.Statistics.Service.Log4Service.Log();
                log.Error("WCFOPScoreQuery SelectOPScore Error:" + ex.Message);
            }

            return null;
        }

        #endregion OP别 总成绩

        #region  OP别 详细成绩
        /// <summary>
        /// OP详细成绩 查询
        /// OPEntryScoreDetailQueryControl.xaml 
        /// 中的DataGrid使用
        /// </summary>
        /// <param name="parameters">parameters 条件参数列表</param>
        /// <returns>返回 ScoreDetailData 的 LIST 形式</returns>
        /// <value> 增加 案件名，线路查询条件 07/06/2011 Add</value>
        public List<ScoreDetailData> SelectOPScoreDetail(WhereParameters parameters)
        {
            try
            {
                #region 参数形式转换
                ////日期
                if (!parameters.WhereentryDateFrom.Equals("null"))
                {
                    parameters.WhereentryDateFrom = parameters.WhereentryDateFrom.ToString().Trim() + " 06:00:00";
                }

                if (!parameters.WhereentryDateTo.Equals("null"))
                {
                    parameters.WhereentryDateTo = parameters.WhereentryDateTo.ToString().Trim() + " 06:00:00";
                }

                ////jobclass
                if (String.IsNullOrEmpty(parameters.WhereJobClass))
                {
                    parameters.WhereJobClass = string.Empty;
                }
                else
                {
                    parameters.WhereJobClass = parameters.WhereJobClass.ToString().Trim();
                }

                ////ScriptType
                if (String.IsNullOrEmpty(parameters.WhereScriptType))
                {
                    parameters.WhereScriptType = string.Empty;
                }
                else
                {
                    parameters.WhereScriptType = parameters.WhereScriptType.ToString().Trim();
                }

                ////WordType
                if (String.IsNullOrEmpty(parameters.WhereWordType))
                {
                    parameters.WhereWordType = string.Empty;
                }
                else
                {
                    parameters.WhereWordType = parameters.WhereWordType.ToString().Trim();
                }

                ////是opid
                if (!string.IsNullOrEmpty(parameters.WhereLoginName))
                {
                    parameters.WhereLoginName = parameters.WhereLoginName.Trim();
                }
                else
                {
                    parameters.WhereLoginName = System.DBNull.Value.ToString();
                }

                ////是UNIT
                if (!string.IsNullOrEmpty(parameters.WhereUnit))
                {
                    parameters.WhereUnit = parameters.WhereUnit.Trim();
                }
                else
                {
                    parameters.WhereUnit = System.DBNull.Value.ToString();
                }

                ////案件名 
                if (!string.IsNullOrEmpty(parameters.WhereMatterName))
                {
                    parameters.WhereMatterName = parameters.WhereMatterName.Trim();
                }
                else
                {
                    parameters.WhereMatterName = DBNull.Value.ToString();
                }

                ////线路
                if (!string.IsNullOrEmpty(parameters.WhereServer))
                {
                    parameters.WhereServer = parameters.WhereServer.Trim();
                }
                else
                {
                    parameters.WhereServer = DBNull.Value.ToString();
                }


                #endregion 参数设置

                return DataProvider.GetSelectEntryScoreDetail(parameters);
            }
            catch (Exception ex)
            {
                Log4Service.Log log = new Orid.Management.Statistics.Service.Log4Service.Log();
                log.Error("WCFOPScoreDetailQuery SelectOPScoreDetail Error:" + ex.Message);
            }

            return null;
        }
        #endregion  OP别 详细成绩


    }
}
